# coding: utf-8
from sqlalchemy import BigInteger, Boolean, Column, DateTime, Float, Integer, JSON, String, Text, text
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()
metadata = Base.metadata


class Conversation(Base):
    __tablename__ = 'conversation'

    id = Column(String(32), primary_key=True, comment='对话框ID')
    name = Column(String(50), comment='对话框名称')
    chat_type = Column(String(50), comment='聊天类型')
    create_time = Column(DateTime, comment='创建时间')


class FileDoc(Base):
    __tablename__ = 'file_doc'

    id = Column(Integer, primary_key=True, server_default=text("nextval('file_doc_id_seq'::regclass)"), comment='ID')
    kb_name = Column(String(50), comment='知识库名称')
    file_name = Column(String(255), comment='文件名称')
    doc_id = Column(String(50), comment='向量库文档ID')
    meta_data = Column(JSON)


class KnowledgeBase(Base):
    __tablename__ = 'knowledge_base'

    id = Column(Integer, primary_key=True, server_default=text("nextval('knowledge_base_id_seq'::regclass)"), comment='知识库ID')
    kb_name = Column(String(50), comment='知识库名称')
    kb_info = Column(String(200), comment='知识库简介(用于Agent)')
    vs_type = Column(String(50), comment='向量库类型')
    embed_model = Column(String(50), comment='嵌入模型名称')
    file_count = Column(Integer, comment='文件数量')
    create_time = Column(DateTime, comment='创建时间')
    kb_type = Column(String, comment='知识库类型(public(公共),person(个人))')
    create_user_id = Column(BigInteger, comment='创建者id')
    create_user_name = Column(String, comment='创建者名称(冗余)')
    kb_nickname = Column(String)
    kb_prop = Column(String)


class KnowledgeFile(Base):
    __tablename__ = 'knowledge_file'

    id = Column(Integer, primary_key=True, server_default=text("nextval('knowledge_file_id_seq'::regclass)"), comment='知识文件ID')
    file_name = Column(String(255), comment='文件名')
    file_ext = Column(String(10), comment='文件扩展名')
    kb_name = Column(String(50), comment='所属知识库名称')
    document_loader_name = Column(String(50), comment='文档加载器名称')
    text_splitter_name = Column(String(50), comment='文本分割器名称')
    file_version = Column(Integer, comment='文件版本')
    file_mtime = Column(Float(53), comment='文件修改时间')
    file_size = Column(Integer, comment='文件大小')
    custom_docs = Column(Boolean, comment='是否自定义docs')
    docs_count = Column(Integer, comment='切分文档数量')
    create_time = Column(DateTime, comment='创建时间')
    create_user_id = Column(Integer)
    create_user_name = Column(String)
    file_status = Column(String, comment='文件状态0-未开始，1-识别中，2-识别完成')
    end_time = Column(DateTime, comment='完成时间')


class Message(Base):
    __tablename__ = 'message'

    id = Column(String(32), primary_key=True, comment='聊天记录ID')
    conversation_id = Column(String(32), index=True, comment='对话框ID')
    chat_type = Column(String(50), comment='聊天类型')
    query = Column(String(4096), comment='用户问题')
    response = Column(String(4096), comment='模型回答')
    meta_data = Column(JSON)
    feedback_score = Column(Integer, comment='用户评分')
    feedback_reason = Column(String(255), comment='用户评分理由')
    create_time = Column(DateTime, comment='创建时间')
    create_user_id = Column(Integer)
    create_user_name = Column(String)


class SummaryChunk(Base):
    __tablename__ = 'summary_chunk'

    id = Column(Integer, primary_key=True, server_default=text("nextval('summary_chunk_id_seq'::regclass)"), comment='ID')
    kb_name = Column(String(50), comment='知识库名称')
    summary_context = Column(String(255), comment='总结文本')
    summary_id = Column(String(255), comment='总结矢量id')
    doc_ids = Column(String(1024), comment='向量库id关联列表')
    meta_data = Column(JSON)


class ZRectifyDatum(Base):
    __tablename__ = 'z_rectify_data'
    __table_args__ = {'comment': '整改台账'}

    id = Column(Integer, primary_key=True, server_default=text("nextval('z_rectify_data_id_seq'::regclass)"), comment='主键id')
    audit_report_name = Column(String(255), comment='审计报告名称')
    audit_report_date = Column(String(255), comment='审计报告发布日期')
    audit_unit = Column(String(255), comment='被审计单位')
    question_type = Column(String(255), comment='问题类型')
    question_summary = Column(String(255), comment='问题概要')
    question_detail = Column(Text, comment='问题详细描述')
    audit_money = Column(String(255), comment='审计风险金额(元)')
    rectify_advice = Column(String(255), comment='整改建议')
    audit_manager = Column(String(255), comment='审计组联系人')
    audit_dept = Column(String(255), comment='责任部门')
    rectify_hand = Column(String(255), comment='整改落实情况')
    recitify_result = Column(String(255), comment='整改结果确认')
    created_time = Column(DateTime, comment='创建时间')
